#include "PlaylistVoteWidget.h"



/*---------------------------------------------------------------------------------------
--	FUNCTION:	PlaylistVoteWidget::PlaylistVoteWidget(Song * theSong,
                                       Playlist * thePlaylist,
                                       PlaylistClient * client) : song(theSong),
                                                                  playlist(thePlaylist),
                                                                  playlistClient(client)
--
--	DATE:			April 07, 2010
--
--	REVISIONS		(Date and Description):
--
--	DESIGNER:		Eric Ribeiro
--
--	PROGRAMMER:		Eric Ribeiro
--
--	RETURNS:
--
--	NOTES:
--		default constructor for the voting GUI
----------------------------------------------------------------------------------------*/
PlaylistVoteWidget::PlaylistVoteWidget(Song * theSong,
                                       Playlist * thePlaylist,
                                       PlaylistClient * client) : song(theSong),
                                                                  playlist(thePlaylist),
                                                                  playlistClient(client)
{
    voteCounter = new QLabel(QString().setNum(song->getVotes()));
    voteButton = new QPushButton("Vote");

    layout = new QHBoxLayout();
    layout->setMargin(5);

    layout->addWidget(voteCounter, Qt::AlignHCenter);
    layout->addWidget(voteButton, Qt::AlignHCenter);

    setLayout(layout);

    connect(voteButton, SIGNAL(clicked()), this, SLOT(voteButtonClicked()));
}

/*---------------------------------------------------------------------------------------
--	FUNCTION:	PlaylistVoteWidget::voteButtonClicked())
--
--	DATE:			April 07, 2010
--
--	REVISIONS		(Date and Description):
--
--	DESIGNER:		Eric Ribeiro
--
--	PROGRAMMER:		Eric Ribeiro
--
--	RETURNS:
--
--	NOTES:
--		Function to use when the voteButton is clicked
----------------------------------------------------------------------------------------*/
void PlaylistVoteWidget::voteButtonClicked()
{
    if (playlistClient != 0)
        playlistClient->sendVote(song->getFilename());
    else
        playlist->voteSong(song->getFilename());

    voteButton->setDisabled(true);
}

/*---------------------------------------------------------------------------------------
--	FUNCTION:	PlaylistVoteWidget::updateVotes ()
--
--	DATE:			April 07, 2010
--
--	REVISIONS		(Date and Description):
--
--	DESIGNER:		Eric Ribeiro
--
--	PROGRAMMER:		Eric Ribeiro
--
--	RETURNS:
--
--	NOTES:
--		Function to use when we want to update the votes on the GUI screen
----------------------------------------------------------------------------------------*/
void PlaylistVoteWidget::updateVotes ()
{
    voteCounter->setText(QString().setNum(song->getVotes()));

    if (song->getVotes() < 1)
        voteButton->setEnabled(true);
}
